<template>
  <div class="app-container">
    <!-- Header 区域 -->
    <cart-header></cart-header>

    <!-- 商品 Item 项组件 -->
    <cart-item v-for='item in computedList' :key="item.id" :item="item"></cart-item>

    <br>
    <br>
    [[test]]
    <br>
    {{ computedList }}
    <br>
    <br>
    {{ computedList2 }}
    <br>
    <br>
    {{ list }}

    <!-- Foote 区域 -->
    <cart-footer></cart-footer>
  </div>
</template>

<script>
import CartHeader from '@/components/cart-header.vue'
import CartFooter from '@/components/cart-footer.vue'
import CartItem from '@/components/cart-item.vue'

import { mapState } from 'vuex'

export default {
  name: 'App',
  components: {
    CartHeader,
    CartFooter,
    CartItem
  },
  created () {
    this.$store.dispatch('cart/asyncUpdateListFromSrv')
  },
  computed: {
    // 获取vuex的cart模块的list对象
    computedList () {
      return this.$store.state.cart.list
    },
    // 上面代码，使用...mapState方式如下：
    ...mapState({
      computedList2: state => state.cart.list
    }),
    // 使用...mapState 将cart.list 与 list计算方法直接绑定 的方式如下：
    ...mapState('cart', ['list'])
  }
}
</script>

<style lang="less" scoped>
.app-container {
  padding: 50px 0;
  font-size: 14px;
}
</style>
